package com.zjs.controller;

import com.github.pagehelper.PageInfo;
import com.zjs.common.bean.PageQuery;
import com.zjs.common.bean.ResponseResult;
import com.zjs.pojo.SysUser;
import com.zjs.service.BcSysUserServiceI;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @类名： SysUserController
 * @说明： TODO
 * @作者：SS 苏帅出品
 * @时间：2019/12/14 14:59
 * @版本：1.0
 */
@Controller
@RequestMapping(value = "user")
public class SysUserController {


    @Autowired
    BcSysUserServiceI bcSysUserServiceI;

    @RequestMapping(value = "findPage.action")
    @ResponseBody
    public Map<String, Object> findUserList(PageQuery query) {

        Map<String, Object> map = new HashMap<>();


        PageInfo<SysUser> allUserBygLimit = bcSysUserServiceI.findAllUserBygLimit(query);

        map.put("total",allUserBygLimit.getTotal());
        map.put("rows",allUserBygLimit.getList());
        return map;
    }

    //检查是否存在用户名
    @RequestMapping(value = "checkUsername.action")
    @ResponseBody
    public Boolean checkUsernameByName(String username){

        return bcSysUserServiceI.isExistsUsername(username);
    }


    //添加
    @RequestMapping(value = "saveUser.action")
    @ResponseBody
    public ResponseResult saveUser(SysUser user,String[] roleIds){



        int i = bcSysUserServiceI.saveUser(user,roleIds);


        if(i>0){
            return new ResponseResult(true,null);
        }

        return new ResponseResult(false,null);
    }

}
